package ute.mvc.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.springframework.format.annotation.DateTimeFormat;

import ute.mvc.util.DateTimeSerializer;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Entity
public class Assignment {
	@Id
	@Column (length = 20)
	private String assignmentId;
	@Column (length = 100, nullable = false)
	private String assignmentName;
	private int timeSubmitAllow;
	
	@JsonSerialize(using = DateTimeSerializer.class)
	@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm:ss")
	private Date startDay;
	
	@JsonSerialize(using = DateTimeSerializer.class)
	@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm:ss")
	private Date endDate;
	
	@Column (length = 10000)
	private String description;
	
	@OneToOne
	@JoinColumn (name = "fileId")
	private MyFile file;
	private int maxPoint;
	
	@JsonIgnore
	@ManyToOne
	@JoinColumn (name="openCourse_SubjectId", nullable = false)
	private OpenCourse_Subject openCourse_Subject;
	
	@ManyToOne
	@JoinColumn (name="lecturerId", nullable = false)
	private User lecturer;
	
	@JsonIgnore
	@ManyToMany
	@JoinTable (name = "Assignment_Class", joinColumns = @JoinColumn(name="AssignmentId"),
			inverseJoinColumns = @JoinColumn(name="classId"))
	private Collection<MyClass> listClass = new ArrayList<MyClass>();
	
	@JsonIgnore
	@OneToMany (mappedBy = "assignment")
	private Collection<Assignment_Student> listAssignment_Student = new ArrayList<Assignment_Student>();
	
	public Collection<Assignment_Student> getListAssignment_Student() {
		return listAssignment_Student;
	}
	public void setListAssignment_Student(
			Collection<Assignment_Student> listAssignment_Student) {
		this.listAssignment_Student = listAssignment_Student;
	}
	public Collection<MyClass> getListClass() {
		return listClass;
	}
	public void setListClass(Collection<MyClass> listClass) {
		this.listClass = listClass;
	}
	public OpenCourse_Subject getOpenCourse_Subject() {
		return openCourse_Subject;
	}
	public void setOpenCourse_Subject(OpenCourse_Subject openCourse_Subject) {
		this.openCourse_Subject = openCourse_Subject;
	}
	public User getLecturer() {
		return lecturer;
	}
	
	public void setLecturer(User lecturer) {
		this.lecturer = lecturer;
	}
	public String getAssignmentId() {
		return assignmentId;
	}
	public void setAssignmentId(String assignmentId) {
		this.assignmentId = assignmentId;
	}
	public String getAssignmentName() {
		return assignmentName;
	}
	public void setAssignmentName(String assignmentName) {
		this.assignmentName = assignmentName;
	}
	public int getTimeSubmitAllow() {
		return timeSubmitAllow;
	}
	public void setTimeSubmitAllow(int timeSubmitAllow) {
		this.timeSubmitAllow = timeSubmitAllow;
	}
	public Date getStartDay() {
		return startDay;
	}
	public void setStartDay(Date startDay) {
		this.startDay = startDay;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public MyFile getFile() {
		return file;
	}
	public void setFile(MyFile file) {
		this.file = file;
	}
	public int getMaxPoint() {
		return maxPoint;
	}
	public void setMaxPoint(int maxPoint) {
		this.maxPoint = maxPoint;
	}
	
}
